/* 
 * File:   staff.h
 * Author: chao
 *
 * Created on 2013年6月12日, 下午7:17
 */

#ifndef CONTACT_H
#define	CONTACT_H

#ifdef	__cplusplus
extern "C"
{
#endif

#define NAME_LENGTH 0x10
#define EMAIL_LENGTH 0x40
#define MOBILE_LENGTH 0x20
#define CONTACT_GROUP_NAME_LENGTH 0x10

#define HOST_LENGTH 0x10
#define HOSTNAME_LENGTH 0x40
#define USER_LENGTH 0x10
#define PASS_LENGTH 0x40
#define HOST_GROUP_NAME_LENGTH 0x40

    typedef struct _host_member host_member;
    typedef struct _host_group host_group;
    typedef struct _staff staff;
    typedef struct _staff_group staff_group;

    /* host type can be monitored */
    enum HOST_TYPE
    {
        M_PROXY, M_REDIS, M_MYSQL
    };

    /* config file type. */
    enum FILE_TYPE
    {
        INETERMINATE, CONTACT_MEMBER, CONTACT_GROUP, CONTACT_GROUP_MEMBER,
        MONITOR_HOST, MONITOR_HOST_GROUP, MONITOR_HOST_PROXY, MONITOR_HOST_MYSQL,
        MONITOR_HOST_REDIS, MONITOR_GROUP_PROXY, MONITOR_GROUP_HOST,
        MONITOR_GROUP_REDIS
    };

    struct _host_member
    {
        enum HOST_TYPE type;
        char host[HOST_LENGTH];
        char hostname[HOSTNAME_LENGTH];
        char user[USER_LENGTH];
        char pass[PASS_LENGTH];
        host_group *group;
        host_member *next;
    };

    struct _host_group
    {
        enum HOST_TYPE type;
        char host_group_name[HOST_GROUP_NAME_LENGTH];
        host_member *host_list;
        host_group *next_host_group;
    };

    struct _staff
    {
        enum FILE_TYPE type;
        char name[NAME_LENGTH];
        char email[EMAIL_LENGTH];
        char mobile[MOBILE_LENGTH];
        staff *next;
    };

    /* group list */


    struct _staff_group
    {
        enum FILE_TYPE type;
        char staff_group_name[CONTACT_GROUP_NAME_LENGTH];
        staff *member;
        staff_group *next_staff_group;
    };

    /* config file cache list */
    typedef struct _cnf_file cnf_file;

    struct _cnf_file
    {
        char *file_name;
        enum FILE_TYPE file_type;
        int fd;
        char *text;
        cnf_file *next;
    };

    void cnf_file_list_init(cnf_file *cnf_file_list);
    int read_file_into_list(cnf_file *config_file_list, char *file_name,
            enum FILE_TYPE cnf_type);
    int scan_and_print_all_cnf(char *m_general_config_dir);


#ifdef	__cplusplus
}
#endif

#endif	/* CONTACT_H */

